#ifndef MODEL3D_HPP
#define MODEL3D_HPP

#include <QMatrix4x4>
#include <iostream>
#include <QString>
#include <QVector3D>
#include <QGLBuffer>

#include "ShadowMapping/PolyList.hpp"

struct boundingBox
{
    QVector3D min;
    QVector3D max;
};

class Model3D
{
    public:

        Model3D();
        void draw();
        void drawSample();
        void init();

        void setName(std::string name);
        const std::string & getName() const;

        const boundingBox & getBoundingBox() const;
        void setBoundingBox(float [3], float [3]);

        QMatrix4x4 getModelView();
        void setModelView(QMatrix4x4 modelView);

        void addColor();
        void addVertex(float vertexCoord);
        void addFace(unsigned int faceIndice);

		unsigned int getVertexArraySize()
        {
			return _vertexArray.size();
        }

    private:

        void initModelView();

        template<typename T> static inline QGLBuffer createVBO(QGLBuffer::Type bufferType, QGLBuffer::UsagePattern usagePattern, std::vector<T> &data)
        {
                QGLBuffer self(bufferType);
                self.create();
                self.bind();
                self.setUsagePattern(usagePattern);
                self.allocate(data.data(), data.size()*sizeof(T));
                return self;
        };

        void bindVBOs();
        void bindVBOsSample();

        std::string _name;
        QMatrix4x4 _modelView;
        boundingBox _box;

        std::vector<GLfloat> _colorArray;
        std::vector<GLfloat> _vertexArray;
        std::vector<GLuint> _indiceArray;

        std::vector<GLfloat> _verticesSampleArray;
        std::vector<GLuint> _indicesSampleArray;

        QGLBuffer _vboVertices;
        QGLBuffer _vboIndices;

        QGLBuffer _vboVerticesSample;
        QGLBuffer _vboIndicesSample;
};

#endif // MODEL3D_HPP
